package com.sanjiahantang.ythshopping.presenter;

import android.content.Context;

import com.sanjiahantang.ythshopping.config.ConfigValue;
import com.sanjiahantang.ythshopping.http.BaseDelegate;
import com.sanjiahantang.ythshopping.http.OkHttpClientManager;
import com.sanjiahantang.ythshopping.model.HomePageMoreModel;
import com.sanjiahantang.ythshopping.utils.Utils;
import com.sanjiahantang.ythshopping.views.HomePageMoreView;
import com.squareup.okhttp.Request;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by ZHY_9 on 2017/6/17.
 */

public class HomePageMorePresenter extends BasePresenter {

    private HomePageMoreView moreView;

    public HomePageMorePresenter(HomePageMoreView moreView) {
        this.moreView = moreView;
        pageCount = 1;
    }

    private int pageCount;

    public int getPageCount() {
        return pageCount;
    }

    public void setPageCount(int pageCount) {
        this.pageCount = pageCount;
    }

    public void getMoreHomePage(final Context context){
        initLoadDialog(context);
        mLoadingDialog.show();
        Map<String, String> param = new HashMap<>();
        param.put("page", String.valueOf(pageCount));
        OkHttpClientManager.postAsyn(context, ConfigValue.APP_IP + "first/goods_list", param, new BaseDelegate.ResultCallback<HomePageMoreModel>() {


            @Override
            public void onError(Request request, Object tag, Exception e) {
                dismiss();
                Utils.showToast(context, e.getMessage());
            }

            @Override
            public void onResponse(HomePageMoreModel response, Object tag) {
                dismiss();
                moreView.getMoreData(response);

            }
        });

    }
}
